﻿using System;
using System.Globalization;
using System.Management;
using System.Data;
using System.Web;
using System.IO;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using AnyOffice.BIZ;
using System.Reflection;
using System.Data.SqlClient;
using log4net;
using blong.WebControls;

namespace AnyOffice.general.system.res_manage
{
    public partial class monitor : ModulePage
    {

        private static ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
      
        private string GetSize(ulong size)
        {
            decimal num = size / 1073741824M;
            return num.ToString("0.00");
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                DirectoryInfo info = new DirectoryInfo(Request.PhysicalApplicationPath);
                string str = info.Root.FullName.Replace(@"\", "");
                ManagementObject obj2 = new ManagementObject("win32_logicaldisk.deviceid=\"" + str + "\"");
                obj2.Get();
                ulong size = (ulong)obj2["Size"];
                ulong num2 = (ulong)obj2["FreeSpace"];
                ulong num3 = size - num2;
                NumberFormatInfo numberFormat = new CultureInfo("en-US", false).NumberFormat;
                numberFormat.NumberDecimalDigits = 0;
                this.litUsedSpace.Text = num3.ToString("n", numberFormat) + "字节 <b>" + this.GetSize(num3) + "G</b>";
                this.litFreeSpace.Text = num2.ToString("n", numberFormat) + "字节 <b>" + this.GetSize(num2) + "G</b>";
                this.litSize.Text = size.ToString("n", numberFormat) + "字节 <b>" + this.GetSize(size) + "G</b>";
                WebChartItem item = new WebChartItem("已用空间", (float)num3, false);
                this.WebChart1.WebChartItems.Add(item);
                item = new WebChartItem("可用空间", (float)num2, true);
                this.WebChart1.WebChartItems.Add(item);
            }
            catch (Exception exception)
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("", exception);
                }
            }
        } 

    }
}
